package Core;

import io.netty.channel.Channel;
import io.netty.channel.ChannelId;

public class NetData {
    public static int PROTOHEADSIZE = 6;

    // 0, proto (google protobuf + 6 head) 1, customize。用来区分是protobuf消息还是内部消息（CMD)
    private NetDataType Type;
    //全局唯一的客户端标志，长ID，根据Netty的方法得到，是IP和其他东西的组合成的字符串
    private String ChannelId;
    private byte[] Data;
    //消息的ID，全局unique
    private int Id;
    private Channel ChannelHandle;

    public NetData(Channel channel, byte[] data, NetDataType type, int id) {
        this.Data = data;
        this.Type = type;
        this.Id = id;
        this.ChannelHandle = channel;
        //根据：https://stackoverflow.com/questions/18262926/howto-get-some-id-for-a-netty-channel
        this.ChannelId = channel.toString();
    }

    public String GetClientId () {
        return ChannelId;
    }

    public byte[] GetData() {
        return Data;
    }

    public NetDataType GetType() {
        return Type;
    }

    public int GetId() { return Id; }

    public Channel GetChannel() {
        return ChannelHandle;
    }
}
